home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / CUJ9209.ARJ / TEST1.CPP < prev    next >
Text File  |  1980-01-08  |  743b  |  50 lines

  1. #include <iostream.h>
  2.  
  3. #include "ExH.h"
  4.  
  5. class Ex1:public Exception {
  6.     int a_value;
  7.  
  8. public:
  9.     Ex1(int v) {a_value = v;}
  10.  
  11.     static int ctype() {return 1;}
  12.     int type() {return 1;}
  13.     int size() {return sizeof(Ex1);}
  14.     int getvalue() {return a_value;}
  15. };
  16.  
  17. void f2(int fail)
  18. {
  19.     if(fail)     // Throw
  20.         ExH::throw(Ex1(10));
  21.  
  22.     cout << "F2 OK\n";
  23. }
  24.  
  25. void f1(int fail)
  26. {
  27.     f2(fail);
  28. }
  29.  
  30. main()
  31. {
  32.     // Try
  33.     if(setjmp(ExH::stk++)==0) {
  34.         f1(0);
  35.         f1(1);
  36.     }
  37.     //Catch
  38.     else if( ExH::lastEx->type() == Ex1::ctype()) {
  39.         Ex1& m = *(Ex1*)ExH::lastEx;
  40.         cout << "Catching Exception type 1. Value = "
  41.                 << m.getvalue() << "\n";
  42.         f1(0);
  43.     }
  44.     else {
  45.         cout << "Bad type\n";
  46.         unexpected();
  47.     }
  48.     cout << "Normal End\n";
  49. }
  50.